#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    int minimumArea(vector<vector<int>>& grid) {
        int mini = INT_MAX;
        int minj = INT_MAX;
        int maxi = 0; int maxj = 0;
        for (int i = 0; i < grid.size(); i++) {
            for (int j = 0; j < grid[0].size(); j++) {
                if (grid[i][j] == 1) {
                    if (i < mini) mini = i;
                    if (j < minj) minj = j;
                    if (i > maxi) maxi = i;
                    if (j > maxj) maxj = j;
                }
            }
        }
        return (maxi - mini + 1) * (maxj - minj + 1);
    }
};